#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from app.libs.enums import ClientTypeEnum
from app.libs.redprint import RedPrint
from app.models.user import User
from app.vaildators.forms import ClientForm, UserEmailForm

view_api = RedPrint('client')


@view_api.route('/register', methods=['POST'])
def create_client():
    form = ClientForm().validate_for_api()

    promise = {
        ClientTypeEnum.USER_EMAIL: __register_user_by_email
    }
    promise[form.type.data]()

    return 'success'


def __register_user_by_email():
    form = UserEmailForm().validate_for_api()

    User.register_by_email(
        form.nickname.data,
        form.account.data,
        form.secret.data
    )
